package com.bw.day_2.login

import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.SPUtils
import com.blankj.utilcode.util.ToastUtils
import com.bw.base.mvvm.BaseActivity
import com.bw.day_2.databinding.ActivityLoginBinding
import com.bw.day_2.login.LoginViewModel
import dagger.hilt.android.AndroidEntryPoint
@Route(path = "/app/LoginActivity")
@AndroidEntryPoint
class LoginActivity : BaseActivity<ActivityLoginBinding, LoginViewModel>() {
    override fun initView() {
        binding.login.setOnClickListener {
            viewModel.login(binding.username.text.toString(),binding.password.text.toString())
        }

    }

    override fun initData() {
        viewModel.loginSuccess.observe(this){
            ToastUtils.showLong("登陆成功")
            SPUtils.getInstance().put("token",it.token)
            ARouter.getInstance().build("/app/MainActivity").navigation()
        }
    }


}